import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import Components from 'unplugin-vue-components/vite'
import { defineConfig } from 'vite'
import { viteMockServe } from 'vite-plugin-mock'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    viteMockServe({
      mockPath: './src/mock/',
      localEnabled: true,
    }),
  ],
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@import "./src/assets/styles/index.scss";',
      },
    },
  },
  resolve: {
    alias: {
      '@': resolve('./src'),
      '@a': resolve('./src/api'),
      '@s': resolve('./src/store'),
      '@r': resolve('./src/router'),
      '@c': resolve('./src/components'),
      '@p': resolve('./src/pages'),
      '@u': resolve('./src/utils'),
    },
  },
  server: {
    host: '0.0.0.0',
    port: 7777,
    // proxy: {
    //   '/api': {
    //     target: 'http://127.0.0.1:3100/', //你要跨域访问的网址
    //     changeOrigin: true, // 允许跨域
    //     rewrite: path => path.replace(/^\/api/, ''), // 重写路径把路径变成空字符 (path) => path.replace(/^\/api/, '')
    //   },
    // },
    // cors: true,
  },
})
